const loadGruntTasks = require('load-grunt-tasks')
const sass = require('sass')


module.exports = grunt => {
  loadGruntTasks(grunt);

  grunt.initConfig({
    copy: {
      fonts: {
        expand: true,
        cwd: 'src/assets/fonts/',
        src: '**',
        dest: 'dist/assets/fonts/',
      },
      images: {
        expand: true,
        cwd: 'src/assets/images/',
        src: '**',
        dest: 'dist/assets/images/',
      },
      extra: {
        expand: true,
        cwd: 'public/',
        src: '**',
        dest: 'dist/',
      }
    },
    useref: {
      html: 'dist/*.html',
      temp: 'dist/'
    },
    swig: {
      production: {
        dest: 'dist/',
        src: ['src/*.html'],
        generateSitemap: false,
        generateRobotstxt: false,
      }
    },
    sass: {
      options: {
        sourceMap: true,
        implementation: sass
      },
      main: {
        files: {
          'dist/assets/styles/main.css': 'src/assets/styles/main.scss'
        }
      }
    },
    babel: {
      options: {
        sourceMap: true,
        presets: ['@babel/preset-env']
      },
      main: {
        files: {
          'dist/assets/scripts/main.js': 'src/assets/scripts/main.js'
        }
      }
    },
    clean: {
      temp: 'temp/**',
      dist: 'dist/**',
    }
  })

  grunt.registerTask('build', ['clean', 'swig', 'sass', 'babel', 'useref', 'concat', 'uglify', 'cssmin', 'copy'])
}
